<template>
  <div>
    <!--搜索框-->
    <div class="pd-10">
      <el-input style="width: 200px" suffix-icon="el-icon-search" placeholder="请输入患者姓名" class="mr-5" v-model="nickname"></el-input>
      <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
      <el-button type="warning" @click="reset">重置</el-button>
    </div>
    <!--新增按钮-->
    <div class="mg-10">
      <!--批量删除-->
      <el-popconfirm
          title="您确定批量删除这些数据吗？"
          @confirm="delBatch">
        <el-button class="ml-5" type="danger" slot="reference">
          <i class="el-icon-remove-outline"></i>批量删除
        </el-button>
      </el-popconfirm>
      <!--导出-->
      <el-button class="ml-5" type="primary" @click="exportFile">
        <i class="el-icon-top"></i>导出
      </el-button>
    </div>
    <el-table :data="tableData" border stripe :header-cell-style="{background: '#cccccc'}"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50">
      </el-table-column>
      <el-table-column prop="id" label="ID" width="50">
      </el-table-column>
      <el-table-column prop="name" label="类型" width="140">
      </el-table-column>
      <el-table-column prop="payPrice" label="实付款" width="120">
      </el-table-column>
      <el-table-column prop="orderNo" label="订单编号" width="120">
      </el-table-column>
      <el-table-column prop="doctorName" label="医生姓名">
      </el-table-column>
      <el-table-column prop="username" label="挂号人姓名">
      </el-table-column>
      <el-table-column prop="payTime" label="支付时间">
      </el-table-column>
      <el-table-column prop="state" label="支付状态">
        <template slot-scope="scope">
          <span style="color: #f3062a;font-weight: bold" v-if="scope.row.state === 0">{{ scope.row.state === 0 ? "未支付" : (scope.row.state === 1 ? "已支付" : "未知") }}</span>
          <span style="color: #3a8ee6;font-weight: bold" v-if="scope.row.state === 1">{{ scope.row.state === 0 ? "未支付" : (scope.row.state === 1 ? "已支付" : "未知") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="280px">
        <template slot-scope="scope">
<!--          <el-button type="success" @click="handleEdit(scope.row)">编辑<i class="el-icon-edit"></i></el-button>-->
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗？"
              @confirm="del(scope.row.id)">
            <el-button type="danger" slot="reference">删除<i class="el-icon-delete"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {serverIp, serverPort} from "../../../public/config";

export default {
  name: "Booking",
  data() {
    return {
      tableData: [],
      nickname:"",
      //分页
      pageNum: 1,
      pageSize: 5,
      total: 0
    }
  },
  methods: {
    load() {
      this.request.get("/order/page",{
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          nickname: this.nickname
        }
      }).then(res => {
        console.log(res);
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    exportFile() {
      window.open(`http://${serverIp}:${serverPort}/order/export`)
    },
    del(id) {
      this.request.delete("/order/"+id).then(res => {
        if (res.code === '200') {
          this.$message.success("删除成功")
          this.load()
        }else {
          this.$message.error("删除失败")
        }
      })
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },
    delBatch() {
      let ids = this.multipleSelection.map(v => v.id)
      this.request.post("/order/del/batch",ids).then(res => {
        if (res.data) {
          this.$message.success("批量删除成功")
          this.load()
        }else {
          this.$message.error("批量删除失败")
        }
      })
    },
    reset() {
      this.nickname = ""
      this.deptId = ""
      this.load()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.load()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val
      this.load()
    }
  },
  created() {
    this.load()
  },
  watch: {
  }

}
</script>

<style>
.el-header {
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>